﻿Imports System.Data.SqlClient
Imports System.Data.OleDb

Public Class SQLProvider
    Shared m_strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\QuanLyKho.mdb;User Id=;Password=;"
    Shared m_connection As OleDbConnection

    Public Shared Sub Open() 'kết nối database
        If m_connection Is Nothing Then
            m_connection = New OleDbConnection(m_strConnection)
        End If
        m_connection.Open()
    End Sub


    Public Shared Sub Close()
        m_connection.Close()
    End Sub

    Public Shared Sub ExecNoneQuery(strSQL As String)
        ' Mở kết nối
        Open()
        'thực thi câu truy vấn
        Dim command As OleDbCommand
        command = New OleDbCommand(strSQL, m_connection)
        command.ExecuteNonQuery()
        'đóng kết nối
        Close()
    End Sub

    Public Shared Function ExecQuery(strSQL As String) As DataTable
        'Mở kết nối
        Open()
        'thực thi câu truy vấn
        Dim adapter As OleDbDataAdapter
        adapter = New OleDbDataAdapter(strSQL, m_connection)
        Dim dt As New DataTable
        adapter.Fill(dt)
        Close()
        Return dt
    End Function

End Class
